﻿#Interactions relating to the education of children


# Designate guardian and ward in your own court
#This interaction is referenced in code! If it's renamed you have to ping a coder
educate_child_interaction = {
	category = interaction_category_friendly
	common_interaction = yes

	send_name = SEND_PROPOSAL


	desc = educate_child_interaction_desc

	redirect = {
		scope:actor = {
			if = {
				limit = {
					is_physically_able_adult = no
					num_of_relation_guardian = 0
				}
				save_scope_as = secondary_recipient
			}
			else_if = {
				limit = {
					is_physically_able_adult = yes
					OR = {
						num_of_relation_ward < 2
						is_ai = no
					}
					NOT = { scope:recipient = scope:secondary_recipient }
				}
				save_scope_as = secondary_actor
			}
			else_if = {
				limit = {
					any_courtier = {
						is_physically_able_adult = yes
						num_of_relation_ward < 2
					}
				}
				random_courtier = {
					limit = {
						is_physically_able_adult = yes
						num_of_relation_ward < 2
					}
					weight = {
						base = 1
						modifier = {
							add = 5
							culture = scope:actor.culture
						}
						modifier = {
							add = 2
							faith = scope:actor.faith
						}
						modifier = {
							add = 10
							has_council_position = councillor_court_chaplain
						}
						modifier = {
							add = 2
							is_councillor = yes
						}
						modifier = {
							add = 3
							this.dynasty = scope:actor.dynasty
						}
						modifier = {
							add = 2
							has_education_rank_4_trigger = yes
						}
						modifier = {
							add = 1
							has_education_rank_3_trigger = yes
						}
					}
					save_scope_as = secondary_actor
				}
			}
			if = {
				limit = {
					exists = employer
					NOT = { employer = scope:actor }
				}
				
				employer = {
					save_scope_as = actor
				}
			}
		}

		scope:recipient = {
			if = {
				limit = {
					is_physically_able_adult = yes
					OR = {
						num_of_relation_ward < 2
						scope:actor = {
							is_ai = no
						}
					}
				}
				save_scope_as = secondary_actor
			}
			else = {
				save_scope_as = secondary_recipient
			}

			if = {
				limit = {
					exists = employer
					NOT = { employer = scope:recipient }
				}
				
				employer = {
					save_scope_as = recipient
				}
			}
		}		
	}

	populate_actor_list = {
		scope:actor = {
			if = {
				limit = {
					is_physically_able_adult = yes
					OR = {
						num_of_relation_ward < 2
						is_ai = no
					}
					is_imprisoned = no
					NOT = { has_trait = incapable }
				}
				add_to_list = characters
			}
			every_courtier = {
				limit = {
					is_physically_able_adult = yes
					OR = {
						num_of_relation_ward < 2
						scope:actor = {
							is_ai = no
						}
					}
					is_imprisoned = no
					NOT = { has_trait = incapable }
				}
				add_to_list = characters
			}
		}
	}

	populate_recipient_list = {
		scope:recipient = {
			if = {
				limit = {
					is_physically_able_adult = no
					num_of_relation_guardian = 0
					is_imprisoned = no
					NOT = { has_trait = incapable }
				}
				add_to_list = characters
			}
			every_courtier = {
				limit = {
					is_physically_able_adult = no
					num_of_relation_guardian = 0
					is_imprisoned = no
					NOT = { has_trait = incapable }
				}
				add_to_list = characters
			}
		}
	}

	greeting = positive
	notification_text = {
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:actor = scope:secondary_actor
					NOT = { scope:recipient = scope:secondary_recipient }
				}
				desc = EDUCATE_RECIPIENT_CHILD_PERSONALLY_REQUEST
			}
			triggered_desc = {
				trigger = {
					scope:actor = scope:secondary_actor
					scope:recipient = scope:secondary_recipient
				}
				desc = EDUCATE_RECIPIENT_PERSONALLY_REQUEST
			}
			triggered_desc = {
				trigger = {
					NOT = { scope:recipient = scope:secondary_recipient }
					NOT = { scope:actor = scope:secondary_actor }
				}
				desc = EDUCATE_RECIPIENT_CHILD_REQUEST
			}
			triggered_desc = {
				trigger = {
					scope:recipient = scope:secondary_recipient
					NOT = { scope:actor = scope:secondary_actor }
				}
				desc = EDUCATE_RECIPIENT_REQUEST
			}
		}
	}
	
	prompt = {
		first_valid = {	
			triggered_desc = {
				trigger = {
					NOT = { exists = scope:secondary_actor }
				}
				desc = EDUCATE_SELECT_YOUR_GUARDIAN
			}
			triggered_desc = {
					trigger = {
						NOT = { exists = scope:secondary_recipient }
					}
				desc = EDUCATE_SELECT_YOUR_WARD
			}
		}
	}

	is_shown = {
		scope:recipient = {
			is_in_the_same_court_as = scope:actor
		}
		trigger_if = {
			limit = {
				exists = scope:secondary_actor
			}
			scope:secondary_actor = {
				is_adult = yes
				OR = {
					num_of_relation_ward < 2
					scope:actor = {
						is_ai = no
					}
				}
			}
		}
		trigger_if = {
			limit = {
				exists = scope:secondary_recipient
			}
			scope:secondary_recipient = {
				is_adult = no
				num_of_relation_guardian = 0
			}
		}
	}

	is_valid_showing_failures_only = {
		scope:recipient = {
			is_imprisoned = no
			NOT = { has_trait = incapable }
			trigger_if = {
				limit = {
					NOT = { this = scope:actor }
				}
				is_courtier_of = scope:actor
			}

		}
		trigger_if = {
			limit = {
				exists = scope:secondary_actor
			}
			scope:secondary_actor = {
				is_imprisoned = no
				NOT = { has_trait = incapable }
			}
		}
		trigger_if = {
			limit = {
				exists = scope:secondary_recipient
			}
			scope:secondary_recipient = {
				is_imprisoned = no
				NOT = { has_trait = incapable }
			}
		}
		custom_description = {
			text = character_to_guard_exists
			subject = scope:actor
			scope:actor = {
				OR = {
					AND = {
						is_ai = no
						any_courtier = {
							is_adult = yes
							is_imprisoned = no
							NOT = { has_trait = incapable }
						}
					}
					AND = {
						is_adult = yes
						is_ai = no
						is_imprisoned = no
						NOT = { has_trait = incapable }
					}
					any_courtier = {
						is_adult = yes
						num_of_relation_ward < 2
						is_imprisoned = no
						NOT = { has_trait = incapable }
					}
					AND = {
						is_adult = yes
						num_of_relation_ward < 2
						is_imprisoned = no
						NOT = { has_trait = incapable }
					}
				}
			}
		}
		custom_description = {
			text = character_to_educate_exists
			object = scope:actor
			scope:actor = {
				OR = {
					any_courtier = {
						is_adult = no
						num_of_relation_guardian = 0
						is_imprisoned = no
						NOT = { has_trait = incapable }
					}
					AND = {
						is_adult = no
						num_of_relation_guardian = 0
						is_imprisoned = no
						NOT = { has_trait = incapable }
					}
				}
			}
		}
	}

	can_be_picked = {
		is_at_home = yes
	}
	
	on_accept = {
		scope:secondary_recipient = {
			save_scope_as = ward
			scope:secondary_actor = { save_scope_as = guardian }
			scope:recipient = { save_scope_as = ward_liege }
			scope:actor = { save_scope_as = guardian_liege }
		}

		educate_child_interaction_effect = yes

		#University?
		if = {
			limit = {
				scope:ward.host = {
					any_realm_province = {
						has_university_building_trigger = yes
					}
				}
			}
			scope:ward = {
				add_character_flag = {
					flag = studying_at_university
					years = 11
				}
			}
		}

		scope:actor = {
			hidden_effect = {
				send_interface_message = {
					type = event_generic_neutral
					title = educate_child_interaction_notification
					left_icon = scope:guardian
					right_icon = scope:ward
					show_as_tooltip = {
						educate_child_interaction_effect = yes
					}
				}
			}
		}
	}

	auto_accept = yes
	
	ai_accept = {
		base = 100
	}
	
	send_option = {
		is_shown = {
			exists = scope:secondary_actor
			exists = scope:secondary_recipient
			NOT = { scope:secondary_actor.culture = scope:secondary_recipient.culture }
		}
		flag = convert_culture
		localization = EDUCATE_CHILD_OPTION_CONVERT_CULTURE
		current_description = {
			first_valid = {
				triggered_desc = {
					trigger = {
						exists = scope:secondary_actor
						scope:secondary_actor = { is_adult = no }
					}
					desc = EDUCATE_CHILD_OPTION_CONVERT_CULTURE_TT_TO_RECIPIENT
				}
				triggered_desc = {
					trigger = {
						exists = scope:secondary_recipient
						scope:secondary_recipient = { is_adult = no }
					}
					desc = EDUCATE_CHILD_OPTION_CONVERT_CULTURE_TT_TO_ACTOR
				}
			}
		}
	}
	send_option = {
		is_shown = {
			exists = scope:secondary_actor
			exists = scope:secondary_recipient
			NOT = { scope:secondary_actor.faith = scope:secondary_recipient.faith }
		}
		flag = convert_faith
		localization = EDUCATE_CHILD_OPTION_CONVERT_FAITH
		current_description = {
			first_valid = {
				triggered_desc = {
					trigger = {
						exists = scope:secondary_actor
						scope:secondary_actor = { is_adult = no }
					}
					desc = EDUCATE_CHILD_OPTION_CONVERT_FAITH_TT_TO_RECIPIENT
				}
				triggered_desc = {
					trigger = {
						exists = scope:secondary_recipient
						scope:secondary_recipient = { is_adult = no }
					}
					desc = EDUCATE_CHILD_OPTION_CONVERT_FAITH_TT_TO_ACTOR
				}
			}
		}
	}
	send_option = {
		is_valid = {
			scope:actor = {
				has_usable_hook = scope:recipient
			}
		}
		flag = education_hook
		localization = EDUCATION_HOOK
	}
	should_use_extra_icon = {
		scope:actor = { has_usable_hook = scope:recipient }
	}
	extra_icon = "gfx/interface/icons/character_interactions/hook_icon.dds"

	send_options_exclusive = no
	
	ai_targets = {
		ai_recipients = self
	}
	ai_target_quick_trigger = {
		adult = no
	}
	ai_frequency = 24
	
	ai_potential = {
		always = yes
	}
	
	ai_will_do = {
		base = 100
		
		modifier = { # Slight preference for older heirs
			add = scope:secondary_recipient.age
		}
		
		modifier = { # Prefer to educate your own heirs
			add = 900
			scope:actor = scope:secondary_actor
			scope:secondary_recipient = {
				is_heir_of = scope:actor
			}
		}
		
		modifier = { # Otherwise, find a good educator for them
			add = 200
			scope:secondary_actor = {
				OR = {
					has_education_rank_4_trigger = yes
					has_education_rank_3_trigger = yes
				}
			}
			scope:secondary_recipient = {
				is_heir_of = scope:actor
			}
		}
		
		modifier = { # Generally prefer your own flesh & blood to educate children
			add = 200
			exists = scope:secondary_actor.dynasty
			exists = scope:actor.dynasty
			scope:secondary_actor.dynasty = scope:actor.dynasty
		}
		
		modifier = { # Also prefer friends & lovers
			add = 100
			scope:secondary_actor = {
				OR = {
					has_relation_lover = scope:actor
					has_relation_friend = scope:actor
					has_secret_relation_lover = scope:actor
					has_relation_soulmate = scope:actor
					has_relation_best_friend = scope:actor
				}
			}
		}

		modifier = { # The AI shouldn't change culture/faith of their children
			add = -1000
			scope:secondary_recipient.culture = scope:actor.culture
			scope:secondary_recipient.faith = scope:actor.faith
			OR = {
				scope:convert_culture = yes
				scope:convert_faith = yes
			}
		}

		modifier = { # If your kids aren't of your culture/faith, make them so!
			add = 900
			scope:secondary_actor.culture = scope:actor.culture
			scope:secondary_actor.faith = scope:actor.faith
			NOR = {
				scope:secondary_recipient.culture = scope:actor.culture
				scope:secondary_recipient.faith = scope:actor.faith
			}
			scope:convert_culture = yes
			scope:convert_faith = yes
		}

		modifier = { # If your kids aren't of your culture/faith, make them so!
			add = 500
			scope:secondary_actor.culture = scope:actor.culture
			NOT = { scope:secondary_recipient.culture = scope:actor.culture }
			scope:convert_culture = yes
		}

		modifier = { # If your kids aren't of your culture/faith, make them so!
			add = 500
			scope:secondary_actor.faith = scope:actor.faith
			NOT = { scope:secondary_recipient.faith = scope:actor.faith }
			scope:convert_faith = yes
		}

		modifier = { # Rivals are not welcome
			add = -1000
			scope:secondary_recipient = {
				OR = {
					has_relation_rival = scope:actor
					has_relation_nemesis = scope:actor
				}
			}
		}

		modifier = { # Random peasants can only dream about educating noble children!
			add = -1000
			scope:actor = {
				is_lowborn = no
			}
			scope:secondary_recipient = {
				is_lowborn = yes
				NOR = {
					is_councillor = yes
					is_knight = yes
				}
			}
		}

		modifier = { # Don't care about random children
			factor = 0
			scope:secondary_recipient = {
				NOT = {
					is_close_family_of = scope:actor
				}
			}
		}
	}
}


#Offer a ward to a landed character
#This interaction is referenced in code! If it's renamed you have to ping a coder
offer_ward_interaction = {
	category = interaction_category_friendly

	desc = offer_ward_interaction_desc

	send_name = SEND_PROPOSAL

	redirect = {
		scope:recipient = {
			if = {
				limit = {
					exists = employer
					NOT = { employer = scope:recipient }
				}
				save_scope_as = secondary_recipient
				employer = {
					save_scope_as = recipient
				}
			}
		}		
	}

	populate_actor_list = {
		scope:actor = {
			if = {
				limit = {
					is_adult = no
					num_of_relation_guardian = 0
				}
				add_to_list = characters
			}
			every_courtier = {
				limit = {
					is_adult = no
					num_of_relation_guardian = 0
				}
				add_to_list = characters
			}
		}
	}

	populate_recipient_list = {
		scope:recipient = {
			if = {
				limit = {
					is_adult = yes
					OR = {
						num_of_relation_ward < 2
						scope:actor = {
							is_ai = no
						}
					}
				}
				add_to_list = characters
			}
			every_courtier = {
				limit = {
					is_adult = yes
					OR = {
						num_of_relation_ward < 2
						scope:actor = {
							is_ai = no
						}
					}
				}
				add_to_list = characters
			}
		}
	}

	greeting = positive
	notification_text = {
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:actor = scope:secondary_actor
					NOT = { scope:recipient = scope:secondary_recipient }
				}
				desc = EDUCATE_ACTOR_REQUEST
			}
			triggered_desc = {
				trigger = {
					scope:actor = scope:secondary_actor
					scope:recipient = scope:secondary_recipient
				}
				desc = EDUCATE_ACTOR_PERSONALLY_REQUEST
			}
			triggered_desc = {
				trigger = {
					NOT = { scope:recipient = scope:secondary_recipient }
					NOT = { scope:actor = scope:secondary_actor }
				}
				desc = EDUCATE_ACTOR_CHILD_REQUEST
			}
			triggered_desc = {
				trigger = {
					scope:recipient = scope:secondary_recipient
					NOT = { scope:actor = scope:secondary_actor }
				}
				desc = EDUCATE_ACTOR_CHILD_PERSONALLY_REQUEST
			}
		}
	}
	
	prompt = {
		first_valid = {	
			triggered_desc = {
				trigger = {
					exists = scope:secondary_actor
					scope:actor = scope:recipient
				}
				desc = EDUCATE_SELECT_YOUR_GUARDIAN
			}
			triggered_desc = {
				trigger = {
					exists = scope:secondary_actor
					scope:secondary_actor = {
						is_adult = no
					}
				}
				desc = EDUCATE_SELECT_THEIR_GUARDIAN
			}
			desc = EDUCATE_SELECT_YOUR_WARD
		}
	}

	is_shown = {
		scope:recipient = {
			NOT = { this = scope:actor }
			is_landed = yes
		}
		trigger_if = {
			limit = {
				exists = scope:secondary_recipient
			}
			scope:secondary_recipient = { is_adult = yes }
		}
	}
	

	is_valid_showing_failures_only = {
		custom_description = {
			text = character_to_guard_exists
			subject = scope:recipient
			scope:recipient = {
				OR = {
					any_courtier = {
						is_adult = yes
						OR = {
							num_of_relation_ward < 2
							scope:actor = {
								is_ai = no
							}
						}
					}
					AND = {
						is_adult = yes
						OR = {
							num_of_relation_ward < 2
							scope:actor = {
								is_ai = no
							}
						}
					}
				}
			}
		}
		custom_description = {
			text = character_to_educate_exists
			object = scope:actor
			scope:actor = {
				OR = {
					any_courtier = {
						is_adult = no
						num_of_relation_guardian = 0
					}
					AND = {
						is_adult = no
						num_of_relation_guardian = 0
					}
				}
			}
		}
		scope:recipient = {
			is_imprisoned = no
			is_diplomatically_available = yes
		}
		trigger_if = {
			limit = {
				exists = scope:secondary_recipient
			}
			scope:secondary_recipient = {
				is_imprisoned = no
				is_diplomatically_available = yes
			}
		}
	}
	
	
	on_accept = {
		scope:secondary_actor = {
			save_scope_as = ward
			scope:secondary_recipient = { save_scope_as = guardian }
			scope:actor = { save_scope_as = ward_liege }
			scope:recipient = { save_scope_as = guardian_liege }
		}

		offer_ward_interaction_effect = yes

		if = {
			limit = {
				scope:ward.host = {
					any_realm_province = {
						has_university_building_trigger = yes
					}
				}
			}
			scope:ward = {
				add_character_flag = {
					flag = studying_at_university
					years = 11
				}
			}
		}

		scope:actor = {
			if = {
				limit = { NOT = { this = scope:recipient } }
				trigger_event = char_interaction.0080
			}
		}
	}

	on_decline = {
		scope:actor = {
			trigger_event = char_interaction.0081
		}
	}
	
	auto_accept = {
		custom_description = {
			text = "spending_hook"
			subject = scope:actor
			object = scope:recipient
			scope:education_hook = yes
			scope:actor = { has_strong_hook = scope:recipient }
		}
	}
	
	ai_accept = {
		base = 0

		# AI should always accept children the Player has jurisdiction over
		# You can always send your own child away
		modifier = {
			add = 200
			scope:secondary_actor = {
				is_adult = no
				is_child_of = scope:actor
			}
			desc = AI_YOUR_OWN_CHILD
		}
		# Including you
		modifier = {
			add = 200
			scope:secondary_actor = scope:actor
			desc = AI_EDUCATE_YOU
		}
		# You can always send your courtier's child away
		modifier = {
			add = 200
			scope:secondary_actor = {
				is_adult = no
				NOT = { is_child_of = scope:actor }
				is_courtier_of = scope:actor
			}
			#But only if you are of interest to the educator. To educate the courtier of a count is of no interest to a foreign emperor.
			scope:secondary_recipient = {
				OR = {
					is_of_major_or_minor_interest_trigger = { CHARACTER = scope:actor }
					is_of_major_or_minor_interest_trigger = { CHARACTER = scope:secondary_actor }
					highest_held_title_tier <= scope:actor.highest_held_title_tier
				}
			}
			desc = AI_YOUR_COURTIER_CHILD
		}

		#Weak hook: extra points
		modifier = {
			scope:education_hook = yes
			add = 100
			scope:actor = { NOT = { has_strong_hook = scope:recipient } }
			desc = SCHEME_WEAK_HOOK_USED
		}
		
		modifier = { # Respect the liege
			add = 50
			scope:recipient = { target_is_liege_or_above = scope:actor }
			desc = EDUCATE_CHILD_ACTOR_IS_MY_LIEGE
		}

		#If the child is theirs they are more likely to accept
		modifier = {
			add = 100
			scope:secondary_actor = {
				is_child_of = scope:recipient
				is_adult = no
			}
			desc = AI_MY_CHILD
		}

		#If the child is the educator's child they should be more likely to accept
		modifier = {
			add = 100
			scope:secondary_actor = {
				is_adult = no
				is_child_of = scope:secondary_recipient
			}
			desc = AI_MY_CHILD
		}

		#Their opinion of you matters!
		opinion_modifier = {
			opinion_target = scope:actor
			who = scope:recipient
			multiplier = 0.5
			desc = AI_OPINION_REASON
		}

		#Make less likely that they accept if they are of another culture
		modifier = {
			add = -10
			trigger = {
				scope:secondary_actor = {
					has_same_culture_group_as = scope:recipient
					NOT = { has_same_culture_as = scope:recipient }
				}
			}
			desc = AI_NOT_CULTURE
		}
		
		modifier = {
			add = -20
			trigger = {
				scope:secondary_actor = {
					NOT = { has_same_culture_group_as = scope:recipient }
				}
			}
			desc = AI_NOT_CULTURE
		}

		#Less likely if they don't like other religion
		modifier = {
			add = {
				value = -5
				if = {
					limit = {
						scope:recipient.faith = {
							faith_hostility_level = {
								target = scope:actor.faith
								value >= faith_hostile_level
							}
						}
					}
					subtract = 5
				}
				if = {
					limit = {
						scope:recipient.faith = {
							faith_hostility_level = {
								target = scope:actor.faith
								value >= faith_evil_level
							}
						}
					}
					subtract = 10
				}
			}
			trigger = {
				NOT = { scope:recipient.faith = scope:actor.faith }
			}
			desc = AI_RELIGION
		}

		#The better the educator is at a skill, the less likely they are to accept
		compare_modifier = {
			trigger = {
				scope:secondary_recipient = {
					diplomacy >= 10
				}
				NOT = { scope:actor = scope:secondary_actor }
			}
			target = scope:secondary_recipient
			value = diplomacy
			step = 4
			multiplier = -0.5
			offset = -2
			max = 0
			desc = AI_GUARDIAN_SKILL_DIPLOMACY
		}
		compare_modifier = {
			trigger = {
				scope:secondary_recipient = {
					martial >= 10
				}
				NOT = { scope:actor = scope:secondary_actor }
			}
			target = scope:secondary_recipient
			value = martial
			step = 4
			multiplier = -0.5
			offset = -2
			max = 0
			desc = AI_GUARDIAN_SKILL_MARTIAL
		}
		compare_modifier = {
			trigger = {
				scope:secondary_recipient = {
					stewardship >= 10
				}
				NOT = { scope:actor = scope:secondary_actor }
			}
			target = scope:secondary_recipient
			value = stewardship
			step = 4
			multiplier = -0.5
			offset = -2
			max = 0
			desc = AI_GUARDIAN_SKILL_STEWARDSHIP
		}
		compare_modifier = {
			trigger = {
				scope:secondary_recipient = {
					intrigue >= 10
				}
				NOT = { scope:actor = scope:secondary_actor }
			}
			target = scope:secondary_recipient
			value = intrigue
			step = 4
			multiplier = -0.5
			offset = -2
			max = 0
			desc = AI_GUARDIAN_SKILL_INTRIGUE
		}
		compare_modifier = {
			trigger = {
				scope:secondary_recipient = {
					learning >= 10
				}
				NOT = { scope:actor = scope:secondary_actor }
			}
			target = scope:secondary_recipient
			value = learning
			step = 4
			multiplier = -0.5
			offset = -2
			max = 0
			desc = AI_GUARDIAN_SKILL_LEARNING
		}

		#The better you as an educator is at a skill, the more likely they are to accept
		compare_modifier = {
			trigger = {
				AND = {
					scope:actor = scope:secondary_actor
					scope:actor = {
						diplomacy >= 11
					}
				}
			}
			target = scope:actor
			value = diplomacy
			step = 4
			multiplier = 0.75
			offset = -5
			min = 0
			desc = AI_GUARDIAN_SKILL_DIPLOMACY
		}
		compare_modifier = {
			trigger = {
				AND = {
					scope:actor = scope:secondary_actor
					scope:actor = {
						martial >= 11
					}
				}
			}
			target = scope:actor
			value = martial
			step = 4
			multiplier = 0.75
			offset = -5
			min = 0
			desc = AI_GUARDIAN_SKILL_MARTIAL
		}
		compare_modifier = {
			trigger = {
				AND = {
					scope:actor = scope:secondary_actor
					scope:actor = {
						stewardship >= 11
					}
				}
			}
			target = scope:actor
			value = stewardship
			step = 4
			multiplier = 0.75
			offset = -5
			min = 0
			desc = AI_GUARDIAN_SKILL_STEWARDSHIP
		}
		compare_modifier = {
			trigger = {
				AND = {
					scope:actor = scope:secondary_actor
					scope:actor = {
						intrigue >= 11
					}
				}
			}
			target = scope:actor
			value = intrigue
			step = 4
			multiplier = 0.75
			offset = -5
			min = 0
			desc = AI_GUARDIAN_SKILL_INTRIGUE
		}
		compare_modifier = {
			trigger = {
				AND = {
					scope:actor = scope:secondary_actor
					scope:actor = {
						learning >= 11
					}
				}
			}
			target = scope:actor
			value = learning
			step = 4
			multiplier = 0.75
			offset = -5
			min = 0
			desc = AI_GUARDIAN_SKILL_LEARNING
		}

		#More/Less likely based on difference in rank between actor and recipient
		modifier = {
			add = 20
			scope:actor = {
				tier_difference = {
					target = scope:recipient
					value = 1
				}
			}
			desc = AI_RANK_DIFF
		}
		modifier = {
			add = 30
			scope:actor = {
				tier_difference = {
					target = scope:recipient
					value = 2
				}
			}
			desc = AI_RANK_DIFF
		}
		modifier = {
			add = 40
			scope:actor = {
				tier_difference = {
					target = scope:recipient
					value = 3
				}
			}
			desc = AI_RANK_DIFF
		}
		modifier = {
			add = 50
			scope:actor = {
				tier_difference = {
					target = scope:recipient
					value = 4
				}
			}
			desc = AI_RANK_DIFF
		}
		modifier = {
			add = 60
			scope:actor = {
				tier_difference = {
					target = scope:recipient
					value = 5
				}
			}
			desc = AI_RANK_DIFF
		}
		modifier = {
			add = -20
			scope:actor = {
				tier_difference = {
					target = scope:recipient
					value = -1
				}
			}
			desc = AI_RANK_DIFF
		}
		modifier = {
			add = -30
			scope:actor = {
				tier_difference = {
					target = scope:recipient
					value = -2
				}
			}
			desc = AI_RANK_DIFF
		}
		modifier = {
			add = -40
			scope:actor = {
				tier_difference = {
					target = scope:recipient
					value = -3
				}
			}
			desc = AI_RANK_DIFF
		}
		modifier = {
			add = -50
			scope:actor = {
				tier_difference = {
					target = scope:recipient
					value = -4
				}
			}
			desc = AI_RANK_DIFF
		}
		modifier = {
			add = -60
			scope:actor = {
				tier_difference = {
					target = scope:recipient
					value = -5
				}
			}
			desc = AI_RANK_DIFF
		}
		
		modifier = {
			add = 50
			scope:recipient = {
				target_is_liege_or_above = scope:actor
				has_dread_level_towards = {
					target = scope:actor
					level = 1
				}
			}
			desc = INTIMIDATED_REASON
		}
		modifier = {
			add = 100
			scope:recipient = {
				target_is_liege_or_above = scope:actor
				has_dread_level_towards = {
					target = scope:actor
					level = 2
				}
			}
			desc = COWED_REASON
		}
		
		modifier = {
			add = 10
			scope:recipient = {
				NOT = { target_is_liege_or_above = scope:actor }
				has_dread_level_towards = {
					target = scope:actor
					level = 1
				}
			}
			desc = INTIMIDATED_REASON
		}
		modifier = {
			add = 20
			scope:recipient = {
				NOT = { target_is_liege_or_above = scope:actor }
				has_dread_level_towards = {
					target = scope:actor
					level = 2
				}
			}
			desc = COWED_REASON
		}
	}
	
	send_option = {
		is_shown = {
			exists = scope:secondary_actor
			exists = scope:secondary_recipient
			NOT = { scope:secondary_actor.culture = scope:secondary_recipient.culture }
		}
		flag = convert_culture
		localization = EDUCATE_CHILD_OPTION_CONVERT_CULTURE
		current_description = {
			first_valid = {
				triggered_desc = {
					trigger = {
						exists = scope:secondary_actor
						scope:secondary_actor = { is_adult = no }
					}
					desc = EDUCATE_CHILD_OPTION_CONVERT_CULTURE_TT_TO_RECIPIENT
				}
				triggered_desc = {
					trigger = {
						exists = scope:secondary_recipient
						scope:secondary_recipient = { is_adult = no }
					}
					desc = EDUCATE_CHILD_OPTION_CONVERT_CULTURE_TT_TO_ACTOR
				}
			}
		}
	}
	send_option = {
		is_shown = {
			exists = scope:secondary_actor
			exists = scope:secondary_recipient
			NOT = { scope:secondary_actor.faith = scope:secondary_recipient.faith }
		}
		flag = convert_faith
		localization = EDUCATE_CHILD_OPTION_CONVERT_FAITH
		current_description = {
			first_valid = {
				triggered_desc = {
					trigger = {
						exists = scope:secondary_actor
						scope:secondary_actor = { is_adult = no }
					}
					desc = EDUCATE_CHILD_OPTION_CONVERT_FAITH_TT_TO_RECIPIENT
				}
				triggered_desc = {
					trigger = {
						exists = scope:secondary_recipient
						scope:secondary_recipient = { is_adult = no }
					}
					desc = EDUCATE_CHILD_OPTION_CONVERT_FAITH_TT_TO_ACTOR
				}
			}
		}
	}
	send_option = {
		is_valid = {
			scope:actor = {
				has_usable_hook = scope:recipient
			}
		}
		flag = education_hook
		localization = EDUCATION_HOOK
	}
	should_use_extra_icon = {
		scope:actor = { has_usable_hook = scope:recipient }
	}
	extra_icon = "gfx/interface/icons/character_interactions/hook_icon.dds"

	send_options_exclusive = no
}

#Request guardianship
offer_guardianship_interaction = {
	category = interaction_category_friendly

	send_name = SEND_PROPOSAL

	desc = offer_guardianship_interaction_desc

	redirect = {
		scope:recipient = {
			if = {
				limit = {
					exists = employer
					NOT = { employer = scope:recipient }
				}
				if = {
					limit = {
						is_adult = no
						#num_of_relation_guardian = 0
					}
					save_scope_as = secondary_recipient
				}
				employer = {
					save_scope_as = recipient
				}
			}
		}		
	}

	populate_actor_list = {
		scope:actor = {
			if = {
				limit = {
					is_adult = yes
					OR = {
						num_of_relation_ward < 2
						is_ai = no
					}
				}
				add_to_list = characters
			}
			every_courtier = {
				limit = {
					is_adult = yes
					OR = {
						num_of_relation_ward < 2
						liege = {
							is_ai = no
						}
					}
				}
				add_to_list = characters
			}
		}
	}

	populate_recipient_list = {
		scope:recipient = {
			if = {
				limit = {
					is_adult = no
					#num_of_relation_guardian = 0
				}
			}
			add_to_list = characters
			every_courtier = {
				limit = {
					is_adult = no
					#num_of_relation_guardian = 0
				}
				add_to_list = characters
			}
		}
	}

	greeting = positive
	notification_text = {
		first_valid = {
			triggered_desc = {
				trigger = {
					# I assign, myself, to educate not you, but your... 
					scope:actor = scope:secondary_actor
					NOT = { scope:recipient = scope:secondary_recipient }
				}
				desc = EDUCATE_RECIPIENT_CHILD_PERSONALLY_REQUEST
			}
			triggered_desc = {
				trigger = {
					# I assign, myself, to educate you, yourself!
					scope:actor = scope:secondary_actor
					scope:recipient = scope:secondary_recipient
				}
				desc = EDUCATE_RECIPIENT_PERSONALLY_REQUEST
			}
			triggered_desc = {
				trigger = {
				# I assign, not myself, to educate not you, but your... 
					NOT = { scope:recipient = scope:secondary_recipient }
					NOT = { scope:actor = scope:secondary_actor }
				}
				desc = EDUCATE_RECIPIENT_CHILD_REQUEST
			}
			triggered_desc = {
				trigger = {
				# I assign, not myself, to educate you, yourself
					scope:recipient = scope:secondary_recipient
					NOT = { scope:actor = scope:secondary_actor }
				}
				desc = EDUCATE_RECIPIENT_REQUEST 
			}
		}
	}
	
	prompt = {
		first_valid = {	
			triggered_desc = {
				trigger = {
					NOT = { exists = scope:secondary_actor }
				}
				desc = EDUCATE_SELECT_YOUR_GUARDIAN
			}
			triggered_desc = {
				trigger = {
					NOT = { exists = scope:secondary_recipient }
				}
				desc = EDUCATE_SELECT_THEIR_WARD
			}
			desc = EDUCATE_SELECT_YOUR_WARD_OR_GUARDIAN
		}
	}

	is_shown = {
		scope:recipient = {
			NOT = { this = scope:actor }
			is_landed = yes
		}
		trigger_if = {
			limit = {
				exists = scope:secondary_recipient
			}
			scope:secondary_recipient = { is_adult = no }
		}
	}
	

	is_valid_showing_failures_only = {
		custom_description = {
			text = character_to_educate_exists
			object = scope:recipient
			scope:recipient = {
				OR = {
					any_courtier = {
						is_adult = no
						#num_of_relation_guardian = 0
					}
					AND = {
						is_adult = no
						#num_of_relation_guardian = 0
					}
				}
			}
		}
		custom_description = {
			text = character_to_guard_exists
			subject = scope:recipient
			scope:recipient = {
				OR = {
					any_courtier = {
						is_adult = yes
						OR = {
							num_of_relation_ward < 2
							scope:actor = {
								is_ai = no
							}
						}
					}
					AND = {
						is_adult = yes
						OR = {
							num_of_relation_ward < 2
							scope:actor = {
								is_ai = no
							}
						}
					}
				}
			}
		}
		scope:recipient = {
			is_imprisoned = no
			is_diplomatically_available = yes
		}
		trigger_if = {
			limit = {
				exists = scope:secondary_recipient
			}
			scope:secondary_recipient = {
				is_imprisoned = no
				is_diplomatically_available = yes
			}
		}
	}
	
	
	on_accept = {
		scope:secondary_actor = {
			save_scope_as = guardian
			scope:secondary_recipient = { save_scope_as = ward }
			scope:actor = { save_scope_as = ward_liege }
			scope:recipient = { save_scope_as = guardian_liege }
		}

		offer_guardianship_interaction = yes
		
		if = {
			limit = {
				scope:ward.host = {
					any_realm_province = {
						has_university_building_trigger = yes
					}
				}
			}
			scope:ward = {
				add_character_flag = {
					flag = studying_at_university
					years = 11
				}
			}
		}

		save_scope_value_as = { #To give right tooltip in char_interaction.0080
			name = offer_guardianship_interaction
			value = yes
		}

		scope:actor = {
			if = {
				limit = { NOT = { this = scope:recipient } }
				trigger_event = char_interaction.0080
			}
		}
	}

	on_decline = {
		scope:actor = {
			trigger_event = char_interaction.0081
			add_opinion = {
				modifier = declined_guardianship_opinion
				target = scope:recipient
				opinion = -15
			}
		}
	}
	
	auto_accept = {
		custom_description = {
			text = "spending_hook"
			subject = scope:actor
			object = scope:recipient
			scope:education_hook = yes
			scope:actor = { has_strong_hook = scope:recipient }
		}
	}
	
	ai_accept = {
		base = -50

		#Weak hook: extra points
		modifier = {
			scope:education_hook = yes
			add = 200
			scope:actor = { NOT = { has_strong_hook = scope:recipient } }
			desc = SCHEME_WEAK_HOOK_USED
		}
		
		modifier = { # Respect the liege
			add = 100
			scope:recipient = { target_is_liege_or_above = scope:actor }
			desc = EDUCATE_CHILD_ACTOR_IS_MY_LIEGE
		}

		#If the child is the educator's child they should be more likely to accept
		modifier = {
			add = 100
			scope:secondary_recipient = {
				is_adult = no
				is_child_of = scope:secondary_actor
			}
			desc = AI_GUARDIANS_OWN_CHILD
		}
		
		modifier = {
			add = -100
			scope:secondary_actor.court_owner = {
				NOR = {
					this = scope:recipient.court_owner
					this = scope:secondary_recipient.court_owner
				}
			}
			NOT = { scope:secondary_recipient = { is_child_of = scope:recipient } }
			NOT = { scope:recipient = { target_is_liege_or_above = scope:actor } }
			desc = AI_FOREIGN_COURT
		}
		
		modifier = {
			add = -200
			scope:secondary_actor.court_owner = {
				NOR = {
					this = scope:recipient.court_owner
					this = scope:secondary_recipient.court_owner
				}
			}
			scope:secondary_recipient = { is_child_of = scope:recipient }
			NOT = { scope:recipient = { target_is_liege_or_above = scope:actor } }
			desc = AI_CHILD_TO_FOREIGN_COURT
		}

		modifier = {
			add = -100
			scope:convert_culture = yes
			scope:secondary_recipient.culture = scope:recipient.culture
			desc = AI_CONVERT_CULTURE
		}

		modifier = {
			add = -100
			scope:convert_faith = yes
			scope:secondary_recipient.faith = scope:recipient.faith
			desc = AI_CONVERT_FAITH
		}

		modifier = {
			add = 50
			scope:recipient = { has_relation_friend = scope:actor }
			desc = AI_YOUR_FRIEND
		}

		modifier = {
			add = -50
			scope:recipient = { has_relation_rival = scope:actor }
			desc = AI_YOUR_RIVAL
		}

		# If the guardian is the child's secret father, the mother is more likely to send them
		modifier = {
			add = 100
			exists = scope:secondary_recipient.mother
			scope:recipient = scope:secondary_recipient.mother
			OR = {
				scope:actor = {
					any_known_secret = {
						OR = {
							secret_type = secret_unmarried_illegitimate_child
							secret_type = secret_disputed_heritage
						}
						exists = secret_target
						secret_target = scope:secondary_recipient
					}
				}
				scope:secondary_recipient = { has_trait = disputed_heritage }
				AND = {
					scope:secondary_recipient = { has_trait = bastard }
					NOT = { exists = scope:secondary_recipient.father }
				}
			}
			exists = scope:secondary_recipient.real_father
			scope:secondary_recipient.real_father = scope:secondary_actor
			desc = AI_YOU_ARE_THE_FATHER
		}

		#Their opinion of you matters!
		opinion_modifier = {
			opinion_target = scope:actor
			who = scope:recipient
			multiplier = 1
			desc = AI_OPINION_REASON
		}

		#Make less likely that they accept you as educator if they are of another culture
		modifier = {
			add = -5
			trigger = {
				scope:actor = {
					this = scope:secondary_actor
					has_same_culture_group_as = scope:recipient
					NOT = { has_same_culture_as = scope:recipient }
				}
			}
			desc = AI_NOT_CULTURE
		}
		
		modifier = {
			add = -10
			trigger = {
				scope:actor = {
					this = scope:secondary_actor
					NOT = { has_same_culture_group_as = scope:recipient }
				}
			}
			desc = AI_NOT_CULTURE
		}

		#Less likely if they don't like other religion
		modifier = {
			add = {
				value = -5
				if = {
					limit = {
						scope:recipient.faith = {
							faith_hostility_level = {
								target = scope:actor.faith
								value >= faith_hostile_level
							}
						}
					}
					subtract = 5
				}
				if = {
					limit = {
						scope:recipient.faith = {
							faith_hostility_level = {
								target = scope:actor.faith
								value >= faith_evil_level
							}
						}
					}
					subtract = 10
				}
			}
			trigger = {
				NOT = { scope:recipient.faith = scope:actor.faith }
			}
			desc = AI_RELIGION
		}

		#The better the educator is at a skill, the more likely they are to accept
		compare_modifier = {
			trigger = {
				scope:secondary_actor = {
					diplomacy >= 11
				}
			}
			target = scope:secondary_actor
			value = diplomacy
			step = 4
			multiplier = 0.75
			offset = -5
			min = 0
			desc = AI_GUARDIAN_SKILL_DIPLOMACY
		}
		compare_modifier = {
			trigger = {
				scope:secondary_actor = {
					martial >= 11
				}
			}
			target = scope:secondary_actor
			value = martial
			step = 4
			multiplier = 0.75
			offset = -5
			min = 0
			desc = AI_GUARDIAN_SKILL_MARTIAL
		}
		compare_modifier = {
			trigger = {
				scope:secondary_actor = {
					stewardship >= 11
				}
			}
			target = scope:secondary_actor
			value = stewardship
			step = 4
			multiplier = 0.75
			offset = -5
			min = 0
			desc = AI_GUARDIAN_SKILL_STEWARDSHIP
		}
		compare_modifier = {
			trigger = {
				scope:secondary_actor = {
					intrigue >= 11
				}
			}
			target = scope:secondary_actor
			value = intrigue
			step = 4
			multiplier = 0.75
			offset = -5
			min = 0
			desc = AI_GUARDIAN_SKILL_INTRIGUE
		}
		compare_modifier = {
			trigger = {
				scope:secondary_actor = {
					learning >= 11
				}
			}
			target = scope:secondary_actor
			value = learning
			step = 4
			multiplier = 0.75
			offset = -5
			min = 0
			desc = AI_GUARDIAN_SKILL_LEARNING
		}

		#More/Less likely based on difference in rank between actor and recipient
		modifier = {
			add = 30
			scope:actor = {
				tier_difference = {
					target = scope:recipient
					value = 1
				}
			}
			desc = AI_RANK_DIFF
		}
		modifier = {
			add = 40
			scope:actor = {
				tier_difference = {
					target = scope:recipient
					value = 2
				}
			}
			desc = AI_RANK_DIFF
		}
		modifier = {
			add = 50
			scope:actor = {
				tier_difference = {
					target = scope:recipient
					value = 3
				}
			}
			desc = AI_RANK_DIFF
		}
		modifier = {
			add = 60
			scope:actor = {
				tier_difference = {
					target = scope:recipient
					value = 4
				}
			}
			desc = AI_RANK_DIFF
		}
		modifier = {
			add = 70
			scope:actor = {
				tier_difference = {
					target = scope:recipient
					value = 5
				}
			}
			desc = AI_RANK_DIFF
		}
		modifier = {
			add = -30
			scope:actor = {
				tier_difference = {
					target = scope:recipient
					value = -1
				}
			}
			desc = AI_RANK_DIFF
		}
		modifier = {
			add = -40
			scope:actor = {
				tier_difference = {
					target = scope:recipient
					value = -2
				}
			}
			desc = AI_RANK_DIFF
		}
		modifier = {
			add = -50
			scope:actor = {
				tier_difference = {
					target = scope:recipient
					value = -3
				}
			}
			desc = AI_RANK_DIFF
		}
		modifier = {
			add = -60
			scope:actor = {
				tier_difference = {
					target = scope:recipient
					value = -4
				}
			}
			desc = AI_RANK_DIFF
		}
		modifier = {
			add = -70
			scope:actor = {
				tier_difference = {
					target = scope:recipient
					value = -5
				}
			}
			desc = AI_RANK_DIFF
		}

		#More likely to accept if you have an alliance
		modifier = {
			add = 40
			scope:actor = { is_allied_to = scope:recipient }
			desc = AI_HAS_ALLIANCE
		}
		
		modifier = {
			add = 50
			scope:recipient = {
				target_is_liege_or_above = scope:actor
				has_dread_level_towards = {
					target = scope:actor
					level = 1
				}
			}
			desc = INTIMIDATED_REASON
		}
		modifier = {
			add = 100
			scope:recipient = {
				target_is_liege_or_above = scope:actor
				has_dread_level_towards = {
					target = scope:actor
					level = 2
				}
			}
			desc = COWED_REASON
		}
		
		modifier = {
			add = 10
			scope:recipient = {
				NOT = { target_is_liege_or_above = scope:actor }
				has_dread_level_towards = {
					target = scope:actor
					level = 1
				}
			}
			desc = INTIMIDATED_REASON
		}
		modifier = {
			add = 20
			scope:recipient = {
				NOT = { target_is_liege_or_above = scope:actor }
				has_dread_level_towards = {
					target = scope:actor
					level = 2
				}
			}
			desc = COWED_REASON
		}
	}
	
	send_option = {
		is_shown = {
			exists = scope:secondary_actor
			exists = scope:secondary_recipient
			NOT = { scope:secondary_actor.culture = scope:secondary_recipient.culture }
		}
		flag = convert_culture
		localization = EDUCATE_CHILD_OPTION_CONVERT_CULTURE
		current_description = {
			first_valid = {
				triggered_desc = {
					trigger = {
						exists = scope:secondary_actor
						scope:secondary_actor = { is_adult = no }
					}
					desc = EDUCATE_CHILD_OPTION_CONVERT_CULTURE_TT_TO_RECIPIENT
				}
				triggered_desc = {
					trigger = {
						exists = scope:secondary_recipient
						scope:secondary_recipient = { is_adult = no }
					}
					desc = EDUCATE_CHILD_OPTION_CONVERT_CULTURE_TT_TO_ACTOR
				}
			}
		}
	}
	send_option = {
		is_shown = {
			exists = scope:secondary_actor
			exists = scope:secondary_recipient
			NOT = { scope:secondary_actor.faith = scope:secondary_recipient.faith }
		}
		flag = convert_faith
		localization = EDUCATE_CHILD_OPTION_CONVERT_FAITH
		current_description = {
			first_valid = {
				triggered_desc = {
					trigger = {
						exists = scope:secondary_actor
						scope:secondary_actor = { is_adult = no }
					}
					desc = EDUCATE_CHILD_OPTION_CONVERT_FAITH_TT_TO_RECIPIENT
				}
				triggered_desc = {
					trigger = {
						exists = scope:secondary_recipient
						scope:secondary_recipient = { is_adult = no }
					}
					desc = EDUCATE_CHILD_OPTION_CONVERT_FAITH_TT_TO_ACTOR
				}
			}
		}
	}
	send_option = {
		is_valid = {
			scope:actor = {
				has_usable_hook = scope:recipient
			}
		}
		flag = education_hook
		localization = EDUCATION_HOOK
	}
	should_use_extra_icon = {
		scope:actor = { has_usable_hook = scope:recipient }
	}
	extra_icon = "gfx/interface/icons/character_interactions/hook_icon.dds"

	send_options_exclusive = no
	
	ai_targets = {
		ai_recipients = vassals
	}
	
	ai_frequency = 24
	
	ai_potential = {
		is_imprisoned = no
		NOT = { has_trait = incapable }
	}
	
	ai_will_do = {
		base = 0
		
		modifier = { # Liege's should want to culture/faith convert their vassal's children
			add = 100
			
			scope:convert_culture = yes
			scope:convert_faith = yes
			
			scope:secondary_actor = {
				culture = scope:actor.culture
				faith = scope:actor.faith
			}
			scope:secondary_recipient = {
				OR = {
					is_heir_of = scope:recipient
					scope:secondary_recipient = scope:recipient
				}
			}
		}
		
		modifier = { # Liege's should want to culture/faith convert their vassal's children
			add = 95
			
			scope:convert_culture = yes
			
			scope:secondary_actor = {
				culture = scope:actor.culture
			}
			scope:secondary_recipient = {
				OR = {
					is_heir_of = scope:recipient
					scope:secondary_recipient = scope:recipient
				}
			}
		}
		
		modifier = { # Liege's should want to culture/faith convert their vassal's children
			add = 90
			
			scope:convert_faith = yes
			
			scope:secondary_actor = {
				faith = scope:actor.faith
			}
			scope:secondary_recipient = {
				OR = {
					is_heir_of = scope:recipient
					scope:secondary_recipient = scope:recipient
				}
			}
		}
		
		modifier = { # Players shouldn't be spammed
			add = -90
			
			scope:secondary_recipient = {
				is_ai = no
			}
		}
		
		modifier = { # Don't ask to convert faith if that's already a thing
			factor = 0
			
			scope:convert_faith = yes
			NOT = { scope:convert_culture = yes }
			
			scope:secondary_recipient = {
				any_relation = {
					faith = scope:actor.faith
					type = guardian
					has_relation_flag = {
						target = scope:secondary_recipient
						relation = ward
						flag = convert_faith
					}
				}
			}
		}
		
		modifier = { # Don't ask to convert culture if that's already a thing
			factor = 0
			
			scope:convert_culture = yes
			NOT = { scope:convert_faith = yes }
			
			scope:secondary_recipient = {
				any_relation = {
					culture = scope:actor.culture
					type = guardian
					has_relation_flag = {
						target = scope:secondary_recipient
						relation = ward
						flag = convert_culture
					}
				}
			}
		}
		
		modifier = { # Don't ask to convert culture and faith if that's already a thing
			factor = 0
			
			scope:convert_culture = yes
			scope:convert_faith = yes
			
			scope:secondary_recipient = {
				any_relation = {
					culture = scope:actor.culture
					faith = scope:actor.faith
					type = guardian
					has_relation_flag = {
						target = scope:secondary_recipient
						relation = ward
						flag = convert_culture
					}
				}
			}
		}
	}
}

remove_guardian_interaction = {
	category = interaction_category_friendly
	desc = remove_guardian_interaction_desc
	
	force_notification = yes
	greeting = positive
	notification_text = REMOVE_GUARDIAN_INTERACTION
	use_diplomatic_range = no

	is_shown = {
		scope:actor = { is_ruler = yes }
		OR = {
			scope:recipient = {
				any_relation = {
					type = ward
					remove_guardian_interaction_visible_ward_trigger = yes
				}
			}
			scope:recipient = {
				remove_guardian_interaction_visible_ward_trigger = yes
				any_relation = { type = guardian always = yes }
			}
		}
	}

	is_valid_showing_failures_only = {
		scope:recipient = {
			#RECIPIENT = GUARDIAN
			trigger_if = {
				limit = { scope:recipient = { is_adult = yes } }

				#Diplo availability/not imprisoned
				#is_diplomatically_available = yes
				
				any_relation = {
					type = ward
					
					remove_guardian_interaction_visible_ward_trigger = yes
					remove_guardian_interaction_available_ward_trigger = yes
				}
				

				#War blocker
				NOR = {
					is_at_war_with = scope:actor
					any_liege_or_above = { is_at_war_with = scope:actor }
				}
			}
			#RECIPIENT = WARD
			trigger_else = {

				#Diplo availability
				remove_guardian_interaction_visible_ward_trigger = yes
				remove_guardian_interaction_available_ward_trigger = yes

				any_relation = {
					type = guardian
					#is_diplomatically_available = yes
				}

				#War blocker
				any_relation = {
					type = guardian
					NOR = {
						is_at_war_with = scope:actor
						any_liege_or_above = { is_at_war_with = scope:actor }
					}
				}
			}
		}

		#Misc
		#scope:actor = { is_imprisoned = no }
	}

	auto_accept = yes

	ai_min_reply_days = 1
	ai_max_reply_days = 3

	on_accept = {
		#Save guardian scope
		if = {
			limit = { scope:recipient = { is_adult = yes } }
			scope:recipient = {
				save_scope_as = guardian
			}
		}
		else = {
			scope:recipient = { every_relation = { type = guardian save_scope_as = guardian } }
		}
		
		#Save ward(s) scope(s)
		scope:guardian = {
			#If the recipient is the ward, always pick them as ward
			if = {
				limit = {
					NOT = { this = scope:recipient }
				}
				scope:recipient = { save_scope_as = ward }
			}
			#If recipient is the guardian, pick a random ward as ward 1 and if there is an additional one, set is as ward 2
			else = {
				random_relation = {
					type = ward
					limit = {
						remove_guardian_interaction_visible_ward_trigger = yes
						remove_guardian_interaction_available_ward_trigger = yes
					}
					save_scope_as = ward
					save_scope_as = secondary_recipient
				}
				if = {
					limit = {
						any_relation = {
							type = ward
							remove_guardian_interaction_visible_ward_trigger = yes
							remove_guardian_interaction_available_ward_trigger = yes
							NOR = {
								this = scope:ward
								scope:ward = scope:recipient #because if we target a specific child, no 2nd ward
							}
						}
					}
					random_relation = {
						type = ward
						limit = {
							remove_guardian_interaction_visible_ward_trigger = yes
							remove_guardian_interaction_available_ward_trigger = yes
							NOR = {
								this = scope:ward
								this = scope:recipient
							}
						}	
						save_scope_as = ward_2		
					}
				}
			}
		}

		#Letter event to guardian
		if = {
			limit = {
				NOT = {
					scope:guardian = scope:actor
				}
			}
			scope:guardian = {
				trigger_event = char_interaction.0090
			}
		}
		
		#Handling the wards and feedback to actor
		scope:actor = {
			send_interface_message = {
				type = event_generic_neutral
				title = remove_guardian_interaction_notification
				left_icon = scope:guardian
				right_icon = scope:ward

				scope:ward = {
					remove_relation_guardian = scope:guardian

					if = {
						limit = {
							NOR = {
								host = liege
								host = scope:ward
							}
						}
						return_to_court = yes
					}
				}
				if = {
					limit = { exists = scope:ward_2 }
					scope:ward_2 = {
						remove_relation_guardian = scope:guardian
						if = {
							limit = {
								NOR = {
									host = liege
									host = scope:ward_2
								}
							}
							return_to_court = yes
						}
					}
				}
				scope:guardian = {
					if = {
						limit = {
							NOR = {
								host = liege
								host = scope:guardian
							}
						}
						return_to_court = yes
					}
				}

				#Was education promised in vassal.2001? Then you get an opinion penalty
				if = {
					limit = {
						exists = scope:ward.var:vassal_2001_requested_educator
						scope:ward.var:vassal_2001_requested_educator = scope:actor
						exists = scope:ward.var:vassal_2001_vassal_making_request
						scope:ward.var:vassal_2001_vassal_making_request = { is_alive = yes }
					}
					scope:ward.var:vassal_2001_vassal_making_request = {
						add_opinion = {
							modifier = insult_opinion
							target = scope:actor
							opinion = low_negative_opinion
						}
					}
				}
			}
		}

		#Remove guardian opinion from guardian/guardian's liege
		#Ward
		if = {
			limit = { scope:actor = scope:ward.liege } #Only show if actor is ward's liege
			guardian_remove_opinion_effect = {
				GUARDIAN = scope:guardian
				WARD = scope:ward
				WARD_LIEGE = scope:ward.liege
			}
		}
		else = {
			hidden_effect = { #Else hide it
				guardian_remove_opinion_effect = {
					GUARDIAN = scope:guardian
					WARD = scope:ward
					WARD_LIEGE = scope:ward.liege
				}
			}
		}
		#Ward_2
		if = {
			limit = {
				exists = scope:ward_2
				scope:actor = scope:ward_2.liege #Only show guardian opinion removed if actor is ward_2's liege
				NOT = { scope:actor = scope:ward.liege } #also don't show it twice if both wards' are actor's
			}
			guardian_remove_opinion_effect = {
				GUARDIAN = scope:guardian
				WARD = scope:ward_2
				WARD_LIEGE = scope:ward_2.liege
			}
		}
		else_if = {
			limit = {
				exists = scope:ward_2
			}
			hidden_effect = { #Else hide it
				guardian_remove_opinion_effect = {
					GUARDIAN = scope:guardian
					WARD = scope:ward_2
					WARD_LIEGE = scope:ward_2.liege
				} 	
			}
		}

		#Make the liege of the ward(s) insulted if actor is not the liege of the ward
		if = {
			limit = {
				NOR = {
					scope:ward.liege = scope:actor
					scope:ward = scope:actor
				}
			}
			scope:ward.liege = {
				add_opinion = {
					modifier = insulted_opinion
					target = scope:actor
					opinion = -15
				}
			}
		}	
		if = {
			limit = {
				exists = scope:ward_2
				NOR = {
					scope:ward_2.liege = scope:actor
					scope:ward_2.liege = scope:ward.liege
					scope:ward_2 = scope:actor
				}
			}
			scope:ward_2.liege = {
				add_opinion = {
					modifier = insulted_opinion
					target = scope:actor
					opinion = -15
				}
			}
		}
	}
}
